<?php
/**
 * CreateTime: 2024/1/15 14:57
 * User:LinQ
 */

namespace App\ApiCall\Wx\Applet;

use Illuminate\Support\Facades\Redis;

class WxAppletExecute
{
    private $client;

    public function __construct()
    {
        $this->client = WxAppletClient::getInstance(config('openapi.wx.applet.appId'),config('openapi.wx.applet.secret'),'https://api.weixin.qq.com/');
    }

    public function getStableAccessToken(){
        $this->client->setRequestType('POST');
        return $this->client->execute('cgi-bin/stable_token',[
            'appid' => config('openapi.wx.applet.app_id'),
            'secret' => config('openapi.wx.applet.secret'),
            'grant_type' => 'client_credential',
            'force_refresh' => config('openapi.wx.applet.get_access_token_type')
        ]);
    }

    public function jscode2session($js_code){
        return $this->client->execute('cgi-bin/stable_token',[
            'appid' => config('openapi.wx.applet.app_id'),
            'secret' => config('openapi.wx.applet.secret'),
            'js_code' => $js_code,
            'grant_type' => 'authorization_code'
        ]);
    }

}